import 'dart:convert';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:wanxiang_app/bean/news_detail_entity.dart';
import 'package:wanxiang_app/bean/normal_entity.dart';
import 'package:wanxiang_app/bean/qa_list_entity.dart';
import 'package:wanxiang_app/utils/common.dart';
import '../../utils/constant.dart';
import '../../utils/network_manager.dart';
import '../../utils/network_url.dart';
import '../../utils/toast_util.dart';
import '../../widgets/myappbar.dart';
import 'package:get/get.dart';
import 'package:html/parser.dart';
import 'package:flutter_html/flutter_html.dart';

class NewsDetailController extends GetxController{

  @override
  void onInit() {
    super.onInit();
    _getInfo();
  }
  @override
  void onClose() {
    super.onClose();
  }
  late NewsDetailData newsDetailData;
  bool isInite = false;
  void _getInfo(){
    DioManager.getInstance().post(ServiceUrl.newsDetail,{
      'id':Get.arguments['id']
    }, (data) async {
      NewsDetailEntity bannerEntity = NewsDetailEntity.fromJson(jsonDecode(data));
      newsDetailData = bannerEntity.data;
      isInite = true;
      update();
    }, (error) {
      ToastUtil.show(error);
    });
  }
}


class NewsDetailPage extends GetView<NewsDetailController>  {
  late NewsDetailController controller ;
  late BuildContext context ;
  @override
  Widget build(BuildContext context1) {

    Get.lazyPut<NewsDetailController>(() => NewsDetailController());
    controller = Get.find();
    context = context1;

    return GetBuilder<NewsDetailController>(
      builder: (_){
        return  Scaffold(
            appBar: MyAppBar(context: context, title: '资讯详情',hasLeading: true,),
            backgroundColor: Colors.white,
            body:_content());
      },
    )
    ;

  }


  Widget _content(){
    return SingleChildScrollView(
        child: Container(
          padding: EdgeInsets.only(left: 20.w,top: 5.h,right: 20.w,bottom: 20.h),
          child: controller.isInite?Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(controller.newsDetailData.title,style: TextStyle(
                fontWeight: FontWeight.bold,
                fontSize: 16.sp
              ),),
              SizedBox(height: 2.h,),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text('来源：'+controller.newsDetailData.platform,style:TextStyle(color: Color(0xFF999999),fontSize: 13.sp)),
                  Text(Common.transferDate(controller.newsDetailData.updateTime) ,style:TextStyle(color: Color(0xFF999999),fontSize: 13.sp)),
                  Row(
                    children: [
                      Image.asset(Constant.IMG_BASE+'eye_open.png',width: 16.w,height: 10.h,),
                      SizedBox(width: 5.w,),
                      Text(controller.newsDetailData.lookNum.toString(),
                          style: TextStyle(color: Color(0xFF999999),fontSize: 13.sp)),
                    ],
                  )
                ],
              ),
              SizedBox(height: 10.h,),
              Html(data: controller.newsDetailData.content)
            ],
          ):Container() ,
        )
    ) ;
  }









}